<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="110px">
      <el-form-item label="查询日期" prop="day">
        <el-date-picker @change="dateChange" v-model="searchDays" type="daterange" range-separator="至"
                start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="选择类型" prop="sceneId">
        <el-select v-model="queryParams.sceneId" placeholder="请选择类型" clearable>
          <el-option v-for="contract in projectArray" :key="contract.id" :label="contract.remark"
            :value="contract.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
      </el-col>
    </el-row>
    <el-table v-loading="loading" :data="tabList" @selection-change="handleSelectionChange">
      <el-table-column label="类型" align="center" prop="remark">
        <template slot-scope="scope">
          <div @click="urlOpenClick(scope.row)" style="color:#1890ff;cursor: pointer;">{{ scope.row.remark }}</div>
        </template>
      </el-table-column>
      <el-table-column label="日期" align="center" prop="day" />
      <el-table-column label="关注量" align="center" prop="sbNum" />
      <el-table-column label="注册量" align="center" prop="rgNum" />
      <el-table-column label="成交单量" align="center" prop="orderNum" />
      <el-table-column label="成交总额" align="center" prop="amount" />
    </el-table>
    <pagination v-show="total > 0" :total="total" :limit.sync="queryParams.pageSize" :page.sync="queryParams.pageNum" layout="prev, pager, next, jumper" @pagination="getList" />
    <!-- 新增 -->
    <el-dialog title="新增" :close-on-click-modal="false" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="11">
            <el-form-item label="类型" prop="remark">
              <el-input v-model="form.remark" placeholder="请输入类型" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submit">保 存</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <el-dialog :title="info.remark" :close-on-click-modal="false" :visible.sync="urlOpen" width="800px" append-to-body>
      <span>{{info.url}}</span>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>
    
  <script>
  import { getTicketSelectList, getTicketList, ticketAdd} from "@/api/wxqrticket/wxqrticket";
  export default {
    name: "Knowledge",
    components: {
    },
    data() {
      return {
        // 遮罩层
        loading: false,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 表格数据
        tabList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
        },
        createTime:null,
        id:'',
        pupopForm:{},
        projectArray:[],
        form:{},
        open:false,
        searchDays:'',
        urlOpen:false,
        rules:{
          remark:[
            { required: true, message: "类型不能为空", trigger: "blur" }
          ],
        },
        info:{},
      };
    },
    created() {
      this.getSelectList();
      this.getList();
    },
    methods: {
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.searchDays = '' 
        this.queryParams.startDay = ''
        this.queryParams.endDay = ''
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 查询列表 */
      getList() {
        this.loading = true;
        getTicketList(this.queryParams).then(response => {
          this.tabList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      getSelectList() {
        getTicketSelectList().then(response => {
          this.projectArray = response.data;
        });
      },
      reset(){
        this.form={}
      },
      //新增
      handleAdd(){
        this.reset()
        this.title = '新增'
        this.open = true
      },
      cancel(){
        this.open = false
        this.urlOpen = false
      },
      submit(){
        this.$refs["form"].validate(valid => {
          if (valid) {
            ticketAdd(this.form).then(response => {
              if (response.msg == "操作成功") {
                this.$message({message: '新增成功',type: 'success'});
                this.open = false;
                this.info = response.data;
                this.urlOpen = true;
                this.getSelectList();
                this.getList()
              }
            });
          }
        });
      },
      urlOpenClick(data){
        this.info = data;
        this.urlOpen = true;
      },
      dateChange(){
        this.queryParams.startDay = this.searchDays ? this.searchDays[0] : '';
        this.queryParams.endDay = this.searchDays ? this.searchDays[1] : '';
      },
    }
  };
  </script>
  <style>
  .popupCont{
      min-height: 80px;
      padding: 10px ;
      font-size: 14px;
      color:#333;
      border-radius: 6px;
      border:1px solid #999;
    }
    .quesEditBtn{
      text-align: center;
    }
  </style>
    